package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.FreightDetailService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.client.domain.mall.FreightDetail;
import com.sun.showcase.client.query.mall.FreightDetailQuery;

@Controller
@RequestMapping(value="/mall/freightDetail") 
public class FreightDetailController{
	
	@Autowired
	private FreightDetailService freightDetailService;
	
	private Result result = new Result();
	/**
	 * 跳转到FreightDetail管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goFreightDetail")
	public String goFreightDetail() {
		return "mall/freightDetail";
	}
	/**
	 * 跳转到FreightDetail新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleFreightDetail")
	public String handleFreightDetail(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/freightDetail_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public FreightDetail showDesc(FreightDetailQuery freightDetailQuery) {
		return freightDetailService.get(freightDetailQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(FreightDetailQuery freightDetailQuery) {
		return freightDetailService.datagrid(freightDetailQuery);
	}
	

	/**
	 * 添加一个FreightDetail
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(FreightDetailQuery freightDetailQuery) {
		Long c = freightDetailService.getExistRangeCount(freightDetailQuery);
		if(c>0) {
			result.setSuccess(false);
			result.setMsg("价格区间 重复！");
			return result;
		}
		freightDetailService.add(freightDetailQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑FreightDetail
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(FreightDetailQuery freightDetailQuery) {
		Long c = freightDetailService.getExistRangeCount(freightDetailQuery);
		if(c>0) {
			result.setSuccess(false);
			result.setMsg("价格区间 重复！");
			return result;
		}
		freightDetailService.update(freightDetailQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除FreightDetail
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(FreightDetailQuery freightDetailQuery) {
		freightDetailService.delete(freightDetailQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除FreightDetail
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(FreightDetailQuery freightDetailQuery) {
		freightDetailService.deletePt(freightDetailQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据FreightDetail
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(FreightDetailQuery freightDetailQuery) {
		List<FreightDetailQuery> list = freightDetailService.listAll(freightDetailQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
